package com.qiyue.admin.entity.base;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.qiyue.admin.constant.AdminCommonConstant;
import com.qiyue.common.model.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by y747718944 on 2018/2/7
 */
@Entity
@Table(name = "base_menu")
@ApiModel("菜单")
public class Menu  extends BaseEntity{


    @Column(name="code",length = 16)
    private String code;

    @Column(name="title",length = 32)
    private String title;

    @Column(name = "parent_id")
    private Long parentId = AdminCommonConstant.ROOT;

    @Column(name="href",length = 32)
    private String href;

    @Column(name="icon",length = 16)
    private String icon;

    @Column(name="type",length = 16)
    private String type;

    @Column(name="description",length = 32)
    private String description;


    @Column(name = "crt_host",length = 16)
    private String crtHost;

    @Column(name = "upd_host",length = 16)
    private String updHost;

    @Column(name="path",length = 32)
    private String path;

    @Column(name = "order_num" , length = 32)
    private Long orderNum;





    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Long getParentId() {
        return parentId;
    }

    public void setParentId(Long parentId) {
        this.parentId = parentId;
    }

    public String getHref() {
        return href;
    }

    public void setHref(String href) {
        this.href = href;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Override
    public String getCrtHost() {
        return crtHost;
    }

    @Override
    public void setCrtHost(String crtHost) {
        this.crtHost = crtHost;
    }

    @Override
    public String getUpdHost() {
        return updHost;
    }

    @Override
    public void setUpdHost(String updHost) {
        this.updHost = updHost;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }



    public Long getOrderNum() {
        return orderNum;
    }

    public void setOrderNum(Long orderNum) {
        this.orderNum = orderNum;
    }

    @ApiModelProperty(value = "主键关联resource_id关系,取消hibernate创建外键关系")
    private Set<ResourceAuthority> resourceAuthority = new HashSet<ResourceAuthority>();

    @OneToMany(cascade=CascadeType.ALL, fetch = FetchType.LAZY, mappedBy="menu")
    @JsonIgnore
    public Set<ResourceAuthority> getResourceAuthority() {
        return resourceAuthority;
    }

    public void setResourceAuthority(Set<ResourceAuthority> resourceAuthority) {
        this.resourceAuthority = resourceAuthority;
    }

    @ApiModelProperty(value = "menu菜单的外键资源键 一对多的关系")
    private Set<Element> elements = new HashSet<Element>();


    @OneToMany(cascade =  CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "menu")
    @JsonIgnore
    public Set<Element> getElements() {
        return elements;
    }

    public void setElements(Set<Element> elements) {
        this.elements = elements;
    }
}
